package cn.hanyx.coder.design.pattern.structural.bridge.demo02.handler;

import cn.hanyx.coder.design.pattern.structural.bridge.demo02.notify.Notification02;
import cn.hanyx.coder.design.pattern.structural.bridge.info.AlertRule;
import cn.hanyx.coder.design.pattern.structural.bridge.info.ApiStatInfo;

/**
 * TpsAlertHandler
 *
 * @author hanyx
 * @date 2020/05/19
 */
public class TpsAlertHandler extends AlertHandler {
    public TpsAlertHandler(AlertRule rule, Notification02 notification) {
        super(rule, notification);
    }

    @Override
    public void check(ApiStatInfo apiStatInfo) {

        long tps = apiStatInfo.getRequestCount() / apiStatInfo.getDurationOfSeconds();
        if (tps > rule.getMatchedRule(apiStatInfo.getApi()).getMaxTps()) {
            notification.notify(apiStatInfo.getApi());
        }
    }
}
